const app = getApp()
Page({
  data: {
    receivedData: '' ,// 用于保存接收的数据
    active:0,
    url:'',
    imgUrl:'http://localhost:8080/file/downLoad?fileName=',
    heart:[],
    article:[],
    heartMark:[],
    question:[]
  },
  onLoad() {
    this.setData({ url: app.globalData.URL });
    const that = this;
    const eventChannel = this.getOpenerEventChannel();
    // 监听事件并在回调中发送请求
    eventChannel.on('acceptDataFromOpenerPage', (res) => {
      // 1. 先更新数据
      this.setData({ receivedData: res.data }, () => {
        // 2. 在setData回调中确保数据已更新
        wx.request({
          url: that.data.url + '/consult/selectAll',
          method: 'GET',
          data: { name: that.data.receivedData }, // 这里能拿到最新值
          success: (resp) => {
            that.setData({heart:resp.data.data.list})
          },
          fail: (err) => {
            console.error('请求失败', err);
          }
        });
      });
    });
  },
  onChange(event){
    const that = this
    switch(event.detail.name){
      case 1:
        wx.request({
          url: that.data.url+'/article/selectAll',
          method:'GET',
          data:{articleName:that.data.receivedData},
          success:(resp)=>{
            that.setData({article:resp.data.data.list})
          }
        })
      case 2:
        wx.request({
          url: that.data.url+'/heartMark/getHeartMark',
          method:'POST',
          data:{name:this.data.receivedData},
          success(resp){
            that.setData({
              heartMark:resp.data.data.list
            })
          }
        })
      case 3:
        wx.request({
          url: that.data.url+'/question/select',
          method:'POST',
          data:{title:this.data.receivedData,pageSize:10000},
          success(resp){
            that.setData({
              question:resp.data.data.list
            })
            console.log(that.data.question);
          }
        })
    }
  }
});